package com.rocksdata.mc.ui.adapter;



import android.content.Context;
import android.widget.ImageView;


import com.ctz.commonframe.entity.ImageItem;
import com.ctz.commonframe.ui.widget.AbsAdapter;
import com.ctz.commonframe.ui.widget.AdapterViewHolder;
import com.ctz.commonframe.utils.GlideApp;
import com.rocksdata.mc.R;

import java.util.List;


public class ImageGridAdapter extends AbsAdapter<ImageItem> {
	private boolean showAddImage;

	public ImageGridAdapter(Context context, List<ImageItem> imageItemList) {
		super(context, imageItemList, R.layout.item_image_grid);
		this.showAddImage = true;
	}

	public ImageGridAdapter(Context context, List<ImageItem> imageItemList, boolean showAddImage) {
		super(context, imageItemList, R.layout.item_image_grid);
		this.showAddImage = showAddImage;
	}

	@Override
	public int getCount() {
		if(datas.size() < 9){
			return showAddImage ? datas.size() + 1 : datas.size();
		}
		return 9;
	}

	@Override
	public void convert(AdapterViewHolder holder, ImageItem data) {
		ImageView imageView = holder.getView(R.id.image);
		GlideApp.with(context).clear(imageView);
		if (showAddImage && holder.getPosition() == datas.size()) {
			imageView.setImageResource(R.mipmap.ic_add_image);
		} else {
			if (data.thumbnailPath != null) {
//				XUtils3ImageDisplayer.display(imageView, data.thumbnailPath);
				GlideApp.with(context).load(data.thumbnailPath).into(imageView);
			} else if (data.imagePath != null) {
//				XUtils3ImageDisplayer.display(imageView, data.imagePath);
				GlideApp.with(context).load(data.imagePath).into(imageView);
			}
		}
	}
}
